package com.kxmall.web.controller.huishou;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.huishou.domain.vo.HsWasteActivityVo;
import com.kxmall.huishou.domain.bo.HsWasteActivityBo;
import com.kxmall.huishou.service.IHsWasteActivityService;
import com.kxmall.common.core.page.TableDataInfo;

/**
 * 废品回收活动息
 *
 * @author kxmall
 * @date 2023-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/huishou/wasteActivity")
public class HsWasteActivityController extends BaseController {

    private final IHsWasteActivityService iHsWasteActivityService;

    /**
     * 查询废品回收活动息列表
     */
    @SaCheckPermission("huishou:wasteActivity:list")
    @GetMapping("/list")
    public TableDataInfo<HsWasteActivityVo> list(HsWasteActivityBo bo, PageQuery pageQuery) {
        return iHsWasteActivityService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出废品回收活动息列表
     */
    @SaCheckPermission("huishou:wasteActivity:export")
    @Log(title = "废品回收活动息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HsWasteActivityBo bo, HttpServletResponse response) {
        List<HsWasteActivityVo> list = iHsWasteActivityService.queryList(bo);
        ExcelUtil.exportExcel(list, "废品回收活动息", HsWasteActivityVo.class, response);
    }

    /**
     * 获取废品回收活动息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("huishou:wasteActivity:query")
    @GetMapping("/{id}")
    public R<HsWasteActivityVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iHsWasteActivityService.queryById(id));
    }

    /**
     * 新增废品回收活动息
     */
    @SaCheckPermission("huishou:wasteActivity:add")
    @Log(title = "废品回收活动息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HsWasteActivityBo bo) {
        if(bo != null){
            bo.setJoinNum(0l);
            bo.setStatus(0l);
        }
        return toAjax(iHsWasteActivityService.insertByBo(bo));
    }

    /**
     * 修改废品回收活动息
     */
    @SaCheckPermission("huishou:wasteActivity:edit")
    @Log(title = "废品回收活动息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HsWasteActivityBo bo) {
        return toAjax(iHsWasteActivityService.updateByBo(bo));
    }

    /**
     * 删除废品回收活动息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("huishou:wasteActivity:remove")
    @Log(title = "废品回收活动息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHsWasteActivityService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
